
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>
       业主信息关系 人员列表
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" th:href="@{/images/favicon.ico}" type="image/x-icon"/>
    <link rel="stylesheet" th:href="@{/css/main.css}" media="all">
    <script type="text/javascript" th:src="@{/lib/loading/okLoading.js}"></script>
    <link rel="stylesheet" th:href="@{/css/bootstrap.css}">
    <!--导入ElementUI样式列表，css样式一般都在页面头部-->
    <link rel="stylesheet" th:href="@{/css/index.css}">

</head>
<body>
<div th:include="/c/footer::copy"></div>

<div class="x-nav" style="margin-left: 20%">
            <span class="layui-breadcrumb">
              <a th:href="@{/index}"><cite>首页</cite></a>
              <a><cite>管理员表</cite></a>
              <a><cite>管理员列表</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"  href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body" id="app" style="margin-left: 20%">
    <div>
        <span class="demonstration">时间范围</span>
        <el-date-picker
                @change="dateChange"
                v-model="selectDate"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :picker-options="pickerOptions">
        </el-date-picker>
        <span class="demonstration">搜索关键字</span>
        <el-input v-model="searchMap.sname" style="width: 20%" placeholder="请输入管理员姓名"></el-input>
        <el-button type="primary" plain @click="searchMap.pageNum=1;search()">搜索</el-button>
    </div>
    <br>
    <xblock>
        <button class="layui-btn layui-btn-danger" @click="delAll()"><i class="layui-icon">&#xe640;</i>批量删除</button>
        <button class="layui-btn" @click="personnel_add('添加','adminadd.html','1000','600')"><i class="layui-icon">&#xe608;</i>添加
        </button>
        <span class="x-right" style="line-height:40px">共有数据：<span class="layui-badge">{{total}}</span> 条</span>
    </xblock>
    <table class="layui-table">
        <thead>
        <tr>
            <th>
                <input type="checkbox" id="allChecked" :checked="checkedIDs.length===managerList.length"
                       @click="allChecked">
            </th>
            <th>
                ID
            </th>
            <th>
                所属小区
            </th>
            <th>
                小区id
            </th>
            <th>
                登陆账号
            </th>
            <th>
                管理员姓名
            </th>
            <th>
                手机号码
            </th>
            <th>
                邮箱
            </th>
            <th>
                角色
            </th>
            <th>
                添加数据的操作管理员
            </th>
            <th>
                创建时间
            </th>
            <th>
                操作
            </th>
        </tr>
        </thead>
        <tbody id="x-img">
        <tr v-for="(manager,index) in managerList">
            <td>
                <input type="checkbox" :id="'id'+manager.estateManagerId" :value="manager.estateManagerId" v-model="checkedIDs">
            </td>
            <td>{{manager.estateManagerId}}</td>
            <td>{{manager.communityName}}</td>
            <td>{{manager.communityId}}</td>
            <td>{{manager.loginName}}</td>
            <td>{{manager.name}}</td>
            <td>{{manager.telephone}}</td>
            <td>{{manager.email}}</td>
            <td>
                    {{manager.roleId == 1?'管理员':'普通用户'}}
            </td>
            <td>{{manager.createName}}</td>
            <td>{{manager.createTime}}</td>
            <td class="td-manage">
                <a title="编辑" href="javascript:;"
                   @click="manager_edit('编辑','adminadd.html',manager.estateManagerId,'1000','600')"
                   class="ml-5" style="text-decoration:none">
                    <i class="layui-icon">&#xe642;</i>
                </a>
                <a title="删除" href="javascript:;" @click="del_one(manager.estateManagerId)"
                   style="text-decoration:none">
                    <i class="layui-icon">&#xe640;</i>
                </a>
            </td>
        </tr>
        </tbody>
    </table>
    <!--    分页-->
    <el-pagination
            background
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :page-size="searchMap.pageSize"
            layout="prev, pager, next,sizes"
            :page-sizes="[2,10,20]"
            style="text-align: right;"
            :total="total">
    </el-pagination>

</div>
<script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
<!--js脚本一般是放在页面尾部-->
<!--Vue js脚本-->
<script th:src="@{/js/vue.js}" charset="utf-8"></script>
<!--引入ElementUI组件库-->
<script th:src="@{/js/index.js}" charset="utf-8"></script>
<!--引入Axios js脚本-->
<script th:src="@{/js/axios.js}" charset="utf-8"></script>
<!--引入时间插件包Momentjs-->
<script th:src="@{/js/moment.min.js}" charset="utf-8"></script>
<script>
    var app = new Vue({
        el: "#app",//声明当前Vue在页面的作用域
        data: {
            checkedIDs: [],
            managerList: [],
            total: 10,
            searchMap: {"startTime": "", "endTime": "", "sname": "", "pageNum": 1, "pageSize": 2},
            selectDate: ['', ''],
            pickerOptions: {
                shortcuts: [{
                    text: '最近一周',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            }
        },
        methods: {
            //分页条件查询小区列表
            search() {
                axios.post("/manager/search", this.searchMap).then((res) => {
                    app.managerList = res.data.data;
                    app.total = res.data.total;
                });
            },
            // // 单个删除
            del_one(estateManagerId) {
                this.$confirm('请问您是否要删除该业主信息?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //把选中的ID封装到集合中
                    this.checkedIDs.push(estateManagerId);
                    //执行删除操作
                    axios.post("/manager/del", this.checkedIDs).then((res) => {
                        console.log(res)
                        if (res.data.flag) {
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                        }
                        //删除成功，把选中的ID列表置为空
                        this.checkedIDs = [];
                        //把页面置为1，重新获取列表数据
                        this.searchMap.pageNum = 1;
                        this.search();
                    });

                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            //  //多选删除
            delAll() {
                this.$confirm('请问您是否要删除选中业主信息?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    //执行删除操作
                    axios.post("/manager/del", this.checkedIDs).then((res) => {
                        if (res.data.flag) {
                            this.$message({
                                type: 'success',
                                message: '删除成功!'
                            });
                        }
                        //删除成功，把选中的ID列表置为空
                        this.checkedIDs = [];
                        //把页面置为1，重新获取列表数据
                        this.searchMap.pageNum = 1;
                        this.search();
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            urlImg(url) {
                return "http://localhost" + url;
            },
            //全选、全不选方法
            allChecked: function () {
                if (this.checkedIDs.length === this.managerList.length) {
                    // 全不选
                    this.checkedIDs = [];

                } else {
                    this.checkedIDs = [];
                    // 全选
                    this.managerList.forEach((item) => {
                        this.checkedIDs.push(item.estateManagerId); // 与checkbox的value统一
                    })
                }
            },
            //handleSizeChange每页数量发生变化后触发的方法
            handleSizeChange(pageSize) {
                this.searchMap.pageSize = pageSize;
                this.search();
            },
            //handleCurrentChange页码变化触发方法
            handleCurrentChange(pageNum) {
                this.searchMap.pageNum = pageNum;
                this.search();
            },
            //时间区间发生改变，searcHMap中时间区间条件也要变化
            dateChange() {
                //没有选择时间区间或者清理时间条件，当前时间区间为空字符串
                if (this.selectDate == null || this.selectDate.length == 0) {
                    this.searchMap.startTime = '';
                    this.searchMap.endTime = '';
                } else {
                    //当时间区间不为空，往searchMap中添加条件
                    if (this.selectDate[0] != null && this.selectDate[0] != '') {
                        this.searchMap.startTime = this.dateFormat(this.selectDate[0]);

                    }
                    if (this.selectDate[1] != null && this.selectDate[1] != '') {
                        this.searchMap.endTime = this.dateFormat(this.selectDate[1]);
                    }
                }

            },
            //日期格式化方法
            //date 要进行格式的日期 ；format 格式化的样式
            dateFormat(date, format) {
                //默认格式化字符串"YYYY-MM-DD HH:mm:ss"
                if (format == null || format == '') {
                    format = "YYYY-MM-DD HH:mm:ss";
                }
                return moment(date).format(format);
            },
            /*添加*/
            personnel_add(title, url, w, h) {
                this.x_admin_show(title, url, w, h);
            },


            //编辑
            manager_edit(title, url, estateManagerId, w, h) {
                url = url + "?estateManagerId=" + estateManagerId;
                this.x_admin_show(title, url, w, h);
            },
            /*弹出层*/
            /*
                参数解释：
                title	标题
                url		请求的url
                id		需要操作的数据id
                w		弹出层宽度（缺省调默认值）
                h		弹出层高度（缺省调默认值）
            */
            x_admin_show(title, url, width, height) {
                if (title == null || title == '') {
                    title = false;
                }
                ;
                if (url == null || url == '') {
                    url = "404.html";
                }
                ;
                if (width == null || width == '') {
                    width = 800;
                }
                ;
                if (height == null || height == '') {
                    height = ($(window).height() - 50);
                }
                ;

                layer.open({
                    type: 2,
                    area: [width + 'px', height + 'px'],
                    fix: false, //不固定
                    maxmin: true,
                    shadeClose: true,
                    shade: 0.4,
                    title: title,
                    content: url,
                    cancel: function (index, layero) {
                        //使用右上角x关闭弹窗层，回调方法，重新加载页面数据，让修改或者新增的数据立马显示在页面上
                        app.search();
                    }
                });
            },
            /*关闭弹出框口*/
            x_admin_close() {
                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            }
        },
        created: function () {//Vue生命周期方法，加载页面时会执行该方法
            layui.use(['laydate', 'element', 'laypage', 'layer'], function () {
                $ = layui.jquery;//jquery
                layer = layui.layer;//弹出层
                okLoading.close($);
                layer.ready(function () { //为了layer.ext.js加载完毕再执行
                    layer.photos({
                        photos: '#x-img'
                    });
                });
            });
            //初始页面获取小区列表信息
            this.search();
        }
    });
</script>

</body>
</html>